package com.example.score.controller;

import com.example.score.account.Account;
import com.example.score.account.Manager;
import com.example.score.entity.LoginDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author fsyj
 */
@RestController
public class LoginController {

    @Autowired
    Manager manager;

    @PostMapping("/login")
    public ResponseEntity<Account> login(@RequestBody LoginDto loginDto) {
        Account verify = manager.verify(loginDto.getAccount(), loginDto.password);
        if (verify == null) {
            return ResponseEntity.badRequest().body(null);
        } else {
            return ResponseEntity.ok(verify);
        }
    }
}
